package com.strawcom.charmring.bean.http;

import com.strawcom.charmring.bean.Calories;
import com.strawcom.charmring.bean.DailySummary;
import com.strawcom.charmring.util.FormatUtil;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ExerciseDetailRequest extends BaseRequest {

	private static final long serialVersionUID = -4586860156441104866L;

	public List<DailySummaryRequest> everyday_detail_tbl;

	public static class DailySummaryRequest {

		/** 日期 yyyyMMdd */
		public String date;
		/** 消耗卡路里列表 每种运动方式一个 */
		public List<CaloriesRequest> exercises;

		public static DailySummaryRequest convertByDailySummary(DailySummary dailySummary) {
			DailySummaryRequest dsr = new DailySummaryRequest();
			dsr.date = dailySummary.getDate();
			final List<CaloriesRequest> exercises = new ArrayList<ExerciseDetailRequest.CaloriesRequest>();
			for (Calories c : dailySummary.getOriginalCalories()) {
				CaloriesRequest cr = CaloriesRequest.convertByCalories(c);
				exercises.add(cr);
			}
			dsr.exercises = exercises;
			return dsr;
		}
	}

	public static class CaloriesRequest {

		/** 运动开始时间 */
		public String starttm;
		/** 运动结束时间 */
		public String endtm;
		/** 运动类型 */
		public int type;

		public float distance;

		public float samplecnt;

		public float calorie;

		public static CaloriesRequest convertByCalories(Calories calories) {
			CaloriesRequest cr = new CaloriesRequest();
			Date date = FormatUtil.parseDate(calories.getRecordTimeInfo(), FormatUtil.HH_mm);
			cr.starttm = FormatUtil.formatDate(date, FormatUtil.HHmmss);
			Date date2 = new Date(date.getTime() + calories.getDuration() * 60000);
			cr.endtm = FormatUtil.formatDate(date2, FormatUtil.HHmmss);
			cr.type = calories.getType();
			cr.distance = calories.getDistance();
			cr.samplecnt = calories.getStep();
			cr.calorie = calories.getCalorie();
			return cr;
		}
	}
}
